using ImageCSharp.Core.Interfaces;
using System.Collections.ObjectModel;

namespace ImageCSharp.Core.Interfaces
{
    /// <summary>
    /// 批处理服务接口
    /// </summary>
    public interface IBatchProcessingService
    {
        /// <summary>
        /// 批处理配置
        /// </summary>
        BatchProcessingConfiguration Configuration { get; set; }

        /// <summary>
        /// 批处理进度事件
        /// </summary>
        event EventHandler<BatchProgressEventArgs> ProgressChanged;

        /// <summary>
        /// 批处理完成事件
        /// </summary>
        event EventHandler<BatchCompletedEventArgs> BatchCompleted;

        /// <summary>
        /// 开始批处理
        /// </summary>
        void StartBatchProcessing(string inputDirectory, string outputDirectory);

        /// <summary>
        /// 取消批处理
        /// </summary>
        void CancelBatchProcessing();

        /// <summary>
        /// 获取批处理状态
        /// </summary>
        BatchProcessingStatus GetStatus();
    }

    /// <summary>
    /// 批处理配置
    /// </summary>
    public class BatchProcessingConfiguration
    {
        public List<IImagePlugin> Plugins { get; set; } = new();
        public string InputDirectory { get; set; } = "";
        public string OutputDirectory { get; set; } = "";
        public bool ResizeImages { get; set; } = false;
        public int TargetWidth { get; set; } = 800;
        public int TargetHeight { get; set; } = 600;
        public bool ConvertFormat { get; set; } = false;
        public string TargetFormat { get; set; } = "png";
        public bool OverwriteExisting { get; set; } = false;
        public int MaxDegreeOfParallelism { get; set; } = Environment.ProcessorCount;
    }

    /// <summary>
    /// 批处理进度事件参数
    /// </summary>
    public class BatchProgressEventArgs : EventArgs
    {
        public int ProcessedCount { get; set; }
        public int TotalCount { get; set; }
        public string CurrentFile { get; set; } = string.Empty;
        public double ProgressPercentage => TotalCount > 0 ? (double)ProcessedCount / TotalCount * 100 : 0;
    }

    /// <summary>
    /// 批处理完成事件参数
    /// </summary>
    public class BatchCompletedEventArgs : EventArgs
    {
        public int ProcessedCount { get; set; }
        public int FailedCount { get; set; }
        public TimeSpan ProcessingTime { get; set; }
        public List<string> FailedFiles { get; set; } = new();
    }

    /// <summary>
    /// 批处理状态
    /// </summary>
    public class BatchProcessingStatus
    {
        public bool IsRunning { get; set; }
        public int ProcessedCount { get; set; }
        public int TotalCount { get; set; }
        public string CurrentFile { get; set; } = string.Empty;
        public DateTime StartTime { get; set; }
        public DateTime? EndTime { get; set; }
    }
}